﻿namespace music.domain.Model
{
	/// <summary>
	/// Оценка песни пользователем
	/// </summary>
	public class Rate
	{
		/// <summary>
		/// Пользователь
		/// </summary>
		public virtual User User { get; set; }
		
		/// <summary>
		/// Песня
		/// </summary>
		public virtual Song Song { get; set; }

		/// <summary>
		/// Оценка
		/// </summary>
		public virtual int RateValue { get; set; }

		#region Equals & GetHashCode

		public override bool Equals(object obj)
		{
			if (ReferenceEquals(null, obj)) return false;
			if (ReferenceEquals(this, obj)) return true;
			if (obj.GetType() != typeof (Rate)) return false;
			return Equals((Rate) obj);
		}

		public virtual bool Equals(Rate other)
		{
			if (ReferenceEquals(null, other)) return false;
			if (ReferenceEquals(this, other)) return true;
			return Equals(other.User, User) && Equals(other.Song, Song);
		}

		public override int GetHashCode()
		{
			unchecked
			{
				int result = (User != null ? User.GetHashCode() : 0);
				result = (result*397) ^ (Song != null ? Song.GetHashCode() : 0);
				return result;
			}
		}
	
		#endregion
	}
}
